package com.vavr.checkincms.common.domain;

import lombok.Getter;

/**
 * BaseResult
 *
 * @since 2.0.0
 */
@Getter
public class BaseResult<T> {
    /**
     * 返回码
     */
    private final String code;

    /**
     * 返回信息
     */
    private final String msg;

    /**
     * 返回对象
     */
    private T data;

    private BaseResult(Result result) {
        this.code = result.getCode();
        this.msg = result.getMsg();
    }

    private BaseResult(Result result, T t) {
        this.code = result.getCode();
        this.msg = result.getMsg();
        this.data = t;
    }

    public static BaseResult of(Result result) {
        return new BaseResult(result);
    }

    /**
     * 构造返回结果
     *
     * @param result {@link Result}
     * @param t t
     * @return {@link BaseResult}
     */
    public static <T> BaseResult<T> of(Result result, T t) {
        return new BaseResult<>(result, t);
    }
}
